package com.mes.cloud.web;

import com.mes.cloud.api.dto.request.SysModuleTreeAddRequest;
import com.mes.cloud.api.dto.request.SysModuleTreeRequest;
import com.mes.cloud.api.dto.request.SysModuleTreeUpdateRequest;
import com.mes.cloud.api.dto.response.ParentTreeDto;
import com.mes.cloud.api.dto.response.SysModuleTreeDto;
import com.mes.cloud.common.HttpReturnEnums;
import com.mes.cloud.common.JsonResult;
import com.mes.cloud.service.SysModuleTreeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zhengyangping
 * @version 2019-07-30 13:43:20
 * @email 407892370@qq.com
 */
@Api(tags = "模块树表", value = "模块树表接口")
@RestController
@RequestMapping(value = "/sysModuleTree")
public class SysModuleTreeController  {

    private SysModuleTreeService sysModuleTreeService;

    @Autowired
    public SysModuleTreeController(SysModuleTreeService sysModuleTreeService) {
        this.sysModuleTreeService = sysModuleTreeService;
    }

    /**
     * 描述 模块树表查询所有
     *
     * @param {sysModuleTreeRequest}
     * @return com.shinho.tntframe.core.common.model.JsonResult<java.util.List < com.shinho.crm.dict.api.dto.response.SysModuleTreeDto>>
     * @author 郑样平
     * @date 2019/8/3 8:51
     */
    @ApiOperation(value = "模块树表查询所有", notes = "模块树表查询所有")
    @PostMapping(value = "/list")
    public JsonResult<List<SysModuleTreeDto>> list(@RequestBody SysModuleTreeRequest sysModuleTreeRequest) {
        List<SysModuleTreeDto> list = sysModuleTreeService.list(sysModuleTreeRequest);
        JsonResult<List<SysModuleTreeDto>> jsonResult = new JsonResult<>();
        return jsonResult.setCode(HttpReturnEnums.Success.value()).setData(list);
    }

    /**
     * 描述 模块树表新增
     *
     * @param {sysModuleTreeRequest]
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author 郑样平
     * @date 2019/8/3 8:51
     */
    @ApiOperation(value = "模块树表新增", notes = "模块树表新增")
    @PostMapping(value = "/add")
    public JsonResult<SysModuleTreeDto> add(@Valid @RequestBody SysModuleTreeAddRequest sysModuleTreeAddRequest) {
        return sysModuleTreeService.insertSelective(sysModuleTreeAddRequest);
    }

    /**
     * 描述 模块树表修改
     *
     * @param {sysModuleTreeRequest]
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author 郑样平
     * @date 2019/8/3 8:52
     */
    @ApiOperation(value = "模块树表修改", notes = "模块树表修改")
    @PostMapping(value = "/update")
    public JsonResult update(@Valid @RequestBody SysModuleTreeUpdateRequest sysModuleTreeUpdateRequest) {
        return sysModuleTreeService.updateSelectiveById(sysModuleTreeUpdateRequest);
    }

    /**
     * 描述 模块树表删除
     *
     * @param {id]
     * @return com.shinho.tntframe.core.common.model.JsonResult
     * @author 郑样平
     * @date 2019/8/3 8:52
     */
    @ApiOperation(value = "模块树表删除", notes = "模块树表删除")
    @ApiImplicitParam(paramType = "String", name = "id", value = "模块树表主键", required = true)
    @GetMapping(value = "delete/{id}")
    public JsonResult delete(@NotEmpty(message = "id 不能为空！") @PathVariable String id) {
        return sysModuleTreeService.deleteById(id);
    }

    /**
     * 描述 模块树表查看详情
     *
     * @param {id]
     * @return com.shinho.tntframe.core.common.model.JsonResult<com.shinho.crm.dict.api.dto.response.SysModuleTreeDto>
     * @author 郑样平
     * @date 2019/8/3 8:52
     */
    @ApiOperation(value = "模块树表查看详情", notes = "模块树表查看详情")
    @ApiImplicitParam(paramType = "String", name = "id", value = "模块树表主键", required = true)
    @GetMapping(value = "get/{id}")
    public JsonResult<SysModuleTreeDto> get(@NotEmpty(message = "id 不能为空！") @PathVariable String id) {
        return sysModuleTreeService.get(id);
    }

    @ApiOperation(value = "返回父级树拼接", notes = "返回父级树拼接")
    @ApiImplicitParam(paramType = "String", name = "id", value = "模块树表主键", required = true)
    @GetMapping(value = "parentTree/{id}")
    public JsonResult<ParentTreeDto> parentTree(@PathVariable String id) {
        return sysModuleTreeService.parentTree(id);
    }
}
